# coding:utf-8
import os
import sys
import time

from PyQt6.QtCore import Qt, QTranslator
from PyQt6.QtWidgets import QApplication
from qfluentwidgets import FluentTranslator


from plugins.ant_das.database_initializer import DatabaseInitializer
from views.common.config import cfg
from app import MainWindow
import resources_rc  # 引入编译后的资源文件

# 使用新的插件化DAS模块
from das.example_usage import run_example

"""
启动类，这里不不需要怎么修改
"""
# 初始化数据库
databaseInitializer = DatabaseInitializer()
databaseInitializer.initialize_database()

# enable dpi scale
if cfg.get(cfg.dpiScale) != "Auto":
    os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "0"
    os.environ["QT_SCALE_FACTOR"] = str(cfg.get(cfg.dpiScale))


# 案例一 ： 使用新的插件化DAS模块
print("数据库已通过插件化的ant_das模块初始化")

# 运行示例代码
run_example()

# create application
app = QApplication(sys.argv)
app.setAttribute(Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings)

# internationalization
locale = cfg.get(cfg.language).value
translator = FluentTranslator(locale)
galleryTranslator = QTranslator()
galleryTranslator.load(locale, "gallery", ".", ":/gallery/i18n")

app.installTranslator(translator)
app.installTranslator(galleryTranslator)

# create main window
w = MainWindow()
w.show()

app.exec()
